package vi.org.rongcloud19test.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.sea_monster.network.AbstractHttpRequest;

import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
import io.rong.message.TextMessage;
import vi.org.rongcloud19test.Bean.Friends;
import vi.org.rongcloud19test.Bean.User;
import vi.org.rongcloud19test.R;
import vi.org.rongcloud19test.adapter.FriendListAdapter;
import vi.org.rongcloud19test.database.UserInfos;
import vi.org.rongcloud19test.utils.Constants;
import vi.org.rongcloud19test.utils.DemoContext;

/**
 * Created by Vicky on 2015/11/17.
 * RongCloudChatTest
 * contact way: 317461087@qq.com
 */
public class FriendListActivity extends Activity implements AdapterView.OnItemClickListener{


    private ListView friendList;
    private FriendListAdapter adapter;
    private UserInfos friend;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friendlist);

        friendList = (ListView)findViewById(R.id.friend_list);
        adapter = new FriendListAdapter(this, Constants.friendsList);
        friendList.setAdapter(adapter);
        friendList.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        if (RongIM.getInstance() != null && DemoContext.getInstance() != null) {
            friend= Constants.friendsList.get(i);
            Log.i("FriendList id",friend.getUserid()+" name: " +friend.getUsername());
            if (friend.getUserid() != null) {
//                RongIM.getInstance().startPrivateChat(FriendListActivity.this, friend.getUserid(),friend.getUsername());
                Intent intent = new Intent(FriendListActivity.this,ConversationActivity.class);
                Bundle bundle = new Bundle();
                //选择的聊天的好友id
                bundle.putString("targetId",friend.getUserid());
                bundle.putSerializable("portrait",friend.getPortrait());
                intent.putExtras(bundle);
                startActivity(intent);
            }
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
